sqlite: add serialize() and deserialize() to DatabaseSync#62579
sqlite: add serialize() and deserialize() to DatabaseSync#62579nodejs-github-bot merged 3 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
9b9212f to
52f29ac
Compare
| } | ||
|
|
||
| unsigned char* buf = | ||
| static_cast<unsigned char*>(sqlite3_malloc64(byte_length)); |
There was a problem hiding this comment.
sqlite3_deserialize() takes ownership of the buffer when passed SQLITE_DESERIALIZE_FREEONCLOSE
sqlite3_deserialize docs:
"If the SQLITE_DESERIALIZE_FREEONCLOSE bit is set in F, then SQLite will invoke sqlite3_free() on the serialization buffer when the database connection closes. If the SQLITE_DESERIALIZE_RESIZEABLE bit is set, then SQLite will try to increase the buffer size using sqlite3_realloc64() if writes on the database cause it to grow larger than M bytes."
There was a problem hiding this comment.
A comment to that effect would be helpful.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62579 +/- ##
==========================================
+ Coverage 89.77% 89.78% +0.01%
==========================================
Files 697 697
Lines 215749 215854 +105
Branches 41304 41319 +15
==========================================
+ Hits 193681 193812 +131
+ Misses 14161 14117 -44
- Partials 7907 7925 +18
🚀 New features to boost your workflow:
|
Add database.serialize() and database.deserialize() methods to DatabaseSync, wrapping the sqlite3_serialize and sqlite3_deserialize C APIs. These allow extracting an in-memory database as a Uint8Array and loading one back, enabling snapshots, cloning, and transfer of databases without filesystem I/O. Refs: nodejs#62575
f1cc0fe to
86127c0
Compare
Signed-off-by: Ali Hassan <ali-hassan27@outlook.com>
|
@geeksilva97 it failed due to async-hooks.test-improper-order 😞 Can you please retrigger CI? |
Commit Queue failed- Loading data for nodejs/node/pull/62579 ✔ Done loading data for nodejs/node/pull/62579 ----------------------------------- PR info ------------------------------------ Title sqlite: add serialize() and deserialize() to DatabaseSync (#62579) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch thisalihassan:sqlite-serialize-deserialize -> nodejs:main Labels c++, author ready, needs-ci, sqlite Commits 3 - sqlite: add serialize() and deserialize() - add ownership comment to deserialize - doc: added mjs samples for sqlite Committers 1 - Ali Hassan <ali-hassan27@outlook.com> PR-URL: https://github.com/nodejs/node/pull/62579 Refs: https://github.com/nodejs/node/issues/62575 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/62579 Refs: https://github.com/nodejs/node/issues/62575 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com> -------------------------------------------------------------------------------- ℹ This PR was created on Fri, 03 Apr 2026 22:24:19 GMT ✔ Approvals: 2 ✔ - James M Snell (@jasnell) (TSC): https://github.com/nodejs/node/pull/62579#pullrequestreview-4075406936 ✔ - Edy Silva (@geeksilva97): https://github.com/nodejs/node/pull/62579#pullrequestreview-4075976951 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2026-04-10T12:26:18Z: https://ci.nodejs.org/job/node-test-pull-request/72602/ - Querying data for job/node-test-pull-request/72602/ ✔ Build data downloaded ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD 4c4c9e7a47..9f0a3e636b main -> origin/main ✔ origin/main is now up-to-date main is out of sync with origin/main. Mismatched commits: - bdc5e4d3c2 tools: improve backport review script - 9f0a3e636b tools: improve backport review script -------------------------------------------------------------------------------- HEAD is now at 9f0a3e636b tools: improve backport review script ✔ Reset to origin/main - Downloading patch for 62579 From https://github.com/nodejs/node * branch refs/pull/62579/merge -> FETCH_HEAD ✔ Fetched commits as 4dc18ef29d2a..607d8c37fb67 -------------------------------------------------------------------------------- [main fc1a691779] sqlite: add serialize() and deserialize() Author: Ali Hassan <ali-hassan27@outlook.com> Date: Sat Apr 4 03:16:53 2026 +0500 4 files changed, 498 insertions(+) create mode 100644 test/parallel/test-sqlite-serialize.js [main 4e332c261c] add ownership comment to deserialize Author: Ali Hassan <ali-hassan27@outlook.com> Date: Sat Apr 4 13:02:39 2026 +0500 1 file changed, 3 insertions(+) [main 5f16fa1eae] doc: added mjs samples for sqlite Author: Ali Hassan <ali-hassan27@outlook.com> Date: Wed Apr 8 18:48:07 2026 +0500 1 file changed, 25 insertions(+) ✔ Patches applied There are 3 commits in the PR. Attempting autorebase. (node:800) [DEP0190] DeprecationWarning: Passing args to a child process with shell option true can lead to security vulnerabilities, as the arguments are not escaped, only concatenated. (Use `node --trace-deprecation ...` to show where the warning was created) Rebasing (2/6) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- sqlite: add serialize() and deserialize()https://github.com/nodejs/node/actions/runs/24261613071 |
|
Landed in 4a41a00 |
Add
serialize()and.deserialize()methods to DatabaseSync, wrapping thesqlite3_serializeandsqlite3_deserialize. These allow extracting an in-memory database as a Uint8Array and loading one back enabling snapshots, cloning, etc..Implemenation Notes:
serialize()wraps the SQLite allocated buffer directly in a V8BackingStoreto avoid copying the entire database.#ifdef V8_ENABLE_SANDBOXfalls back to a copy path since that configuration forbids external backing stores.deserialize()must copy once because SQLite requiressqlite3_malloc64allocated memory.Wrote test cases with Claude & GPT 5.4
Refs: #62575